VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "filemonitorevent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private WithEvents Monitor As filemonitors ' Declare the FileMonitor with event handling
Attribute Monitor.VB_VarHelpID = -1

' Initialize the FileMonitor instance
Public Sub Initialize(monitorInstance As filemonitors)
    Set Monitor = monitorInstance ' Assign the FileMonitor object
End Sub

' Handle the FileReceived event

Private Sub Monitor_FileReceived()
    ' Optional: Speak notification if sound is enabled
    If IsSoundEnabled() Then
        Dim voice As Object
        Set voice = CreateObject("SAPI.SpVoice")
        voice.Speak "Message has arrived  Warning Check Running Packet Program to ensure total message received before opening"
    End If

    ' Update Label42 on Form1
    mainmenu.Label1.Caption = "Message has arrived"
    mainmenu.Label2.Caption = " Warning Check Packet Program to ensure total message received before opening"
    mainmenu.Label1.Visible = True
    mainmenu.Label2.Visible = True

    ' Start blinking
    mainmenu.Timer2.enabled = True ' Enable the timer
    Debug.Print "Monitor_FileReceived triggered at: " & Now
    Debug.Print "Label1.Caption: " & mainmenu.Label1.Caption
    Debug.Print "Label2.caption:" & mainmenu.Label2.Caption
    Debug.Print "Timer2.Enabled: " & mainmenu.Timer2.enabled

    ' Force File1 to refresh its file list
    If Not received Is Nothing Then
        If received.Visible Then
            Debug.Print "Refreshing File1 on Form5"
            received.File1.Path = "" ' Clear the path first
            received.File1.Path = Monitor.folderpath ' Reassign folder path
            received.File1.Refresh ' Refresh the file list
            Debug.Print "File1 refreshed: Path = " & received.File1.Path & ", Count = " & received.File1.ListCount
        End If
    End If

    ' Update Label42's state again (redundant but retained)
    mainmenu.Label1.Caption = "A Message Has Arrived "
    mainmenu.Label1.Visible = True

    ' Explicitly stop blinking (if needed)
    mainmenu.Timer2.enabled = False
    Debug.Print "Monitor_FileReceived triggered - Timer2.Enabled: " & mainmenu.Timer2.enabled
    Debug.Print "Label1.Caption: " & mainmenu.Label1.Caption
    Debug.Print "Label1.Visible: " & mainmenu.Label1.Visible
End Sub
 
 


